package com.ken.checkviolationapp.ui.home

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.ken.base_http_library.Data
import com.ken.base_http_library.IllegalBean
import com.ken.base_http_library.ServiceCreator
import com.ken.base_http_library.ServiceCreator.Companion.BASE_URL
import com.ken.base_http_library.callback.OnDesCallback
import com.ken.base_http_library.http_api_impl.Destiny
import com.ken.base_http_library.http_api_service.CheckViolationService
import com.ken.base_http_library.response.BaseResponse
import com.ken.base_library.utils.ShowToast
import com.medtap.network.library.IOTransFormHelper.RxStreamHelper

class HomeViewModel(bean: IllegalBean) : ViewModel() {
    val TAG = HomeViewModel::class.java.name
    private val service =
        ServiceCreator.mInstance.get(BASE_URL).create(CheckViolationService::class.java)
    var mResponse = MutableLiveData<BaseResponse<Data>>()
    private val mBean = bean

    fun getData(bean: IllegalBean?, callback: OnDesCallback<Data>) {
        if (bean != null) {
            return service.query(bean.carno, bean.cartype, bean.engineno, bean.frameno)
                .compose(RxStreamHelper().io_Main())
                .map {
                    it
                }.subscribe(Destiny(callback))

        } else {
            ShowToast.show("参数为空")
        }

    }

}